<template>
	<view class="page">
		<view>
			
			<view style="width: 100%;">
				<view style="width: 90%;margin: 20px auto;border: 1px solid #f4f4f4;line-height: 57px;">
					<view style="display: flex;border-bottom: 1px solid #f4f4f4" >
						<view style="width: 30%;border-right: 0.5px solid #f4f4f4;">
							<text style="margin-left: 10px;">+86</text>
						</view>
						<view style="margin-left: 20px;">
							<text>{{rawData.userTel}}</text>
						</view>
					</view>
					<view style="display: flex;">
						<view style="width: 30%;border-right: 0.5px solid #f4f4f4;">
							<text style="margin-left: 10px;">验证码</text>
						</view>
						<view style="margin-left: 20px;margin-top: 20px;">
							<input type="text" @finish="finish" v-model="code" value="" placeholder="请输入验证码" />
						</view>
					</view>
					<view style="float: right;margin-top: -55px;margin-right: 5px;">
						<view >
							<span @click='getCode' v-if="this.getFlag==true" >获取验证码</span>
							<span  v-else style="margin-right: 20px;color: #DD524D;">{{this.temaNum}}</span>
						</view>
					</view>
				</view>
				<view class="u-m-t-50" style="display: flex;">
					<u-button :loading="tixianFlag" type='warning' @click='cancellationBtn' shape='circle' style="background: linear-gradient(270deg, #1ad074e0 0%, #0a9851 53%, #06723c 100%);width: 80%;" >确定注销</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				agreeMent:{},
				userTel:null,
				loadFlag: false,
				phoneFrom: {
					loginName: null,
				},
				temaNum: 60,
				getFlag:true,
				code:null,
				loadFlag: false,
				tixianFlag:false,
			}
		},
		onShow() {
			// let _this = this;
			// let rawData = uni.getStorageSync('rawData');
			this.rawData = uni.getStorageSync('rawData')
			console.log(this.rawData)
			if (rawData) {
				// rawData = JSON.parse(rawData)
				_this.name = rawData.userNickname
				_this.phone = rawData.userTel
				_this.login = true
			}else{
				_this.name = null
				_this.phone = null
				_this.login = false
			}
			this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
		},
		methods: {
			//短信校验
				cancellationBtn(){
					this.tixianFlag=true;
					uni.request({
						url: 'https://admin.515f.com/api/rest/v1/venusOaSysCashOutService/checkCashOutVerificationCode',
						method: 'POST',
						data: {
							tel:this.rawData.userTel,
						    code:this.code
						},
						success: res => {
							if(res.data.code===0){
								// this.$refs.uToast.show({
								// 	title: '验证成功',
								// 	type: 'success',
								// 	icon: false
								// })
								this.$request.api.cancellation({
									user_id:uni.getStorageSync('rawData').userId,
									userSpecialist:0,//是否是专家
								}).then(res =>{
									console.log(res)
									if(res.data.code === 0){
										console.log('11')
										console.log("退出")
										let _this = this
										uni.clearStorage();
										this.phone = null;
										this.name = null;
										// 进入首页
										uni.clearStorageSync();
										uni.reLaunch({//跳转页面
											url:"/pages/user/user"
										})
										// this.$request.api.out({}).then(res => {
										// 	if (res.status == 200) {
										// 		uni.removeStorageSync('rawData');
										// 		uni.removeStorageSync('uuid');
										// 		uni.removeStorageSync('loginTime');
										
										// 		// #ifdef H5
										// 		location.reload();
										// 		// #endif
										
										// 		// #ifdef APP-PLUS
										// 		let _this = this
										// 		uni.clearStorage();
										// 		this.phone = null;
										// 		this.name = null;
										// 		// 进入首页
										// 		uni.clearStorageSync();
										// 		uni.reLaunch({//跳转页面
										// 			url:"/pages/user/user"
										// 		})
										// 		// #endif
										
										// 	}
										// })
									}
								})
								
							}else{
								this.tixianFlag=false;
								this.$refs.uToast.show({
									title: '验证失败',
									type: 'error',
									icon: false
								})
							}
						}
					})
					
					
				},
				// 倒计时
				timeBtn() {
					let _this = this;
					if (this.temaNum == 0) {
						clearTimeout(this.setName)
						 _this.getFlag=true
					} else {
						this.setName = setTimeout(() => {
							--_this.temaNum
							_this.timeBtn()
						}, 1000)
					}
				
				},
				// 获取验证码
				getCode() {
					this.loadFlag = true
					uni.request({
						url: 'https://admin.515f.com/api/rest/v1/venusOaSysCashOutService/cashOutSendVerificationCode',
						method: 'POST',
						data: {tel:this.rawData.userTel},
						success: res => {
							this.loadFlag = false
							this.getFlag=false
							this.temaNum=60
							this.timeBtn()
						}
					})
				},
				
			// }
		}
	}
</script>

<style lang="scss">
.page{
	margin-top: 20rpx;
	background-color: #FFFFFF;
	width: 100vw;
	height: 100vh;
	padding: 0 34rpx;
	.title{
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		padding-top: 68rpx;
		margin-bottom: 20rpx;
		text-align: center;
	}
	.cont{
		font-size: 28rpx;
		font-weight: 400;
		color: #666666;
		// text-indent: 65rpx;		
		line-height: 42rpx;
	}
}
</style>
